#!/usr/bin/env python

#
#    Copyright (c) 2007-2009 Corey Goldberg (corey@goldb.org)
#    License: GNU GPLv3
#
#    This file is part of Pylot.
#    
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.  See the GNU General Public License 
#    for more details.
#


import sys
import core.config as config
import core.optionparse as optionparse




opt, args = optionparse.parse()

opt.debug=opt.debug and opt.blocking



if opt.gui:  # gui mode
    import ui.gui as pylot_gui
    pylot_gui.main(opt)


elif opt.port:  # xml-rpc listener mode   
    import SimpleXMLRPCServer
    import ui.blocking as pylot_blocking
    class RemoteStarter:
        def start(self):
            return pylot_blocking.main(opt)
    rs = RemoteStarter()
    server = SimpleXMLRPCServer.SimpleXMLRPCServer(('localhost', port))
    server.register_instance(rs)
    print 'Pylot - listening on port', port
    print 'waiting for xml-rpc start command...\n'
    server.serve_forever()


elif opt.blocking:  # blocked output mode (stdout blocked until test finishes, then result is returned)
    import ui.blocking as pylot_blocking
    try:    
        pylot_blocking.main(opt)
    except KeyboardInterrupt:
        print '\nInterrupt'
        sys.exit(1)
        
else:  # console/shell mode
    import ui.console as pylot_console
    print '\n-------------------------------------------------'
    print 'Test parameters:'
    print '  number of agents:          %s' % opt.agents
    print '  test duration in seconds:  %s' % opt.duration
    print '  rampup in seconds:         %s' % opt.rampup
    print '  interval in milliseconds:  %s' % opt.interval
    print '  test case xml:             %s' % opt.xmlfile
    print '  log messages:              %s' % opt.log_msgs
    if opt.name:
        print '  test name:                 %s' % opt.name
    if opt.output_dir:
        print '  output directory:           %s' % opt.output_dir
    print '\n'
    try:    
        pylot_console.main(opt)
    except KeyboardInterrupt:
        print '\nInterrupt'
        sys.exit(1)
    
    
